<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class filemanager_model extends CI_Model
{
	function __construct()
    {
        parent::__construct();
    }
	
	function getAllFile($num=30,$offset=0)
	{
		 $this->db->order_by('img_id','DESC');
		 $query = $this->db->get('sys_images',$num,$offset);
		 return $query->result();
	}
	
	function getNumFile()
	{
		 $query = $this->db->get('sys_images');
		 return $query->num_rows();
	} 
	
	function upload()
	{
		$this->load->library('upload_library');
		$size = $_FILES["filedata"]["size"];
		if($size > 0)
		{
			$filedata = $this->upload_library->uploadfile();
			if($filedata!='')
			{
				$file = explode('*',$filedata);
				$data['lb_name'] = $file[0];
				$data['lb_url'] = $file[1];
				$data['ext'] = $file[2] ;
				$data['dt_create'] = date('Y-m-d H:i:s') ;
				  
				$this->db->insert('sys_images',$data);
				return $data['lb_name'];
			}
		}
		else
		{
		  	return '';
		}
	}     
}
?>
